﻿using Api.Application.Command.User;
using Api.DTO;
using AutoMapper;
using Domain;
using ErrorCode;
using Infrastructure;
using MediatR;

namespace Api.Application.Handler.User
{
    public class GetDelHandler : IRequestHandler<GetDelCommand, ApiPaging<UserDTO>>
    {
        private readonly IBase<UserModel> userRepo;
        private readonly IMapper mapper;

        public GetDelHandler(IBase<UserModel> userRepo, IMapper mapper)
        {
            this.userRepo = userRepo;
            this.mapper = mapper;
        }
        public Task<ApiPaging<UserDTO>> Handle(GetDelCommand request, CancellationToken cancellationToken)
        {
            ApiPaging<UserDTO> result = new ApiPaging<UserDTO>();
            var user = userRepo.GetAll().Where(x => x.DeionId == request.DeionId);
            var model = mapper.Map<List<UserDTO>>(user);
            result.Data = model;
            result.Code = ApiEnum.OK;
            result.Msg = "根据部门id查用户";
            return Task.FromResult(result);
        }
    }
}
